import Types from '../actionTypes';

import {
  getGroupnoTree,
  getSupplierData,
  getLogisticsTemplate,
  getSpecChangeData,
  editGoodData, seachGoodsData
} from '../../api';

// 一层

// 一层4级
const GET_FROUP_NO_TREE = (level) => {
  return new Promise((resolve, reject) => {
    getGroupnoTree(level)
      .then(res => {
        resolve({
          type: Types.GET_FROUP_NO_TREE,
          data: res.data
        });
      })
      .catch(err => {
        console.log(err);
      });
  });
};


// 获取供应商数据
const GET_SOPPLIER_DATA = () => {
  return new Promise((resolve, reject) => {
    getSupplierData()
      .then(res => {
        resolve({
          type: Types.GET_SOPPLIER_DATA,
          data: res.data
        });
      })
      .catch(err => {
        console.log(err);
      });
  });
};


// 获取快递模板
const GET_LOGISTICS_TEMPLATE = id => {
  return new Promise((resolve, reject) => {
    getLogisticsTemplate(id)
      .then(res => {
        resolve({
          type: Types.GET_LOGISTICS_TEMPLATE,
          data: res.data
        });
      })
      .catch(err => {
        console.log(err);
      });
  });
};

// 获取规格改变之后的选项
const GET_SPEC_CHANGE_DATA = id => {
  return new Promise((resolve, reject) => {
    getSpecChangeData(id)
      .then(res => {
        console.log(res);
        resolve({
          type: Types.GET_SPEC_CHANGE_DATA,
          data: res.data
        });
      })
      .catch(err => {
        console.log(err);
      });
  });

};

// 符文本内容
const BRAFT_EDITOR_CONTENT = content => {
  return {
    type: Types.BRAFT_EDITOR_CONTENT,
    content
  };
};

// 获取单条商品数据

const EDIT_GOOD_DATA = id => {
  return new Promise((resolve, reject) => {
    editGoodData(id)
      .then(res => {
        resolve({
          type: Types.EDIT_GOOD_DATA,
          data: res.data
        });
      })
      .catch(err => {
        console.log(err);
      });
  });

};


export default {
  GET_FROUP_NO_TREE,
  GET_SOPPLIER_DATA,
  GET_LOGISTICS_TEMPLATE,
  GET_SPEC_CHANGE_DATA,
  BRAFT_EDITOR_CONTENT,
  EDIT_GOOD_DATA
};
